define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'student_information/index' + location.search,
                    add_url: 'student_information/add',
                    edit_url: 'student_information/edit',
                    del_url: 'student_information/del',
                    multi_url: 'student_information/multi',
                    import_url: 'student_information/import',
                    table: 'student_information',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                search:false,
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'room.title', title: __('Class_room'), operate: 'LIKE'},
                        {field: 'teacher.nickname', title: '老师', operate: 'LIKE'},
                        {field: 'student_number', title: __('Student_number'), operate: 'LIKE'},
                        {field: 'RC_NUM', title: __('RC_NUM')},
                        {field: 'sex', title: __('Sex'), searchList: {"1":__('Sex 1'),"2":__('Sex 2')}, formatter: Table.api.formatter.normal},
                        {field: 'grade', title: __('Grade'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {

            var id = $('#cid').val();
            var pname = $('#pname').val();

            html = '';
            $.ajax({
                //请求方式
                type : "POST",
                dataType: "json",
                url : "student_information/point",
                data : {id:id},
                success : function(result) {
                    $.each(result, function(index, value) {
                        if(value.name==pname)
                        {
                            html+='<option value="'+value.name+'" selected >'+value.name+'</option>';
                        }
                        else
                        {
                            html+='<option value="'+value.name+'" >'+value.name+'</option>';
                        }
                    });

                    $('#c-point').html(html);
                },
                error : function(e){
                    console.log(e.status);
                    console.log(e.responseText);
                }

            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {

                $(document).on("change", "#c-circuit_id", function(){
                    var id = $(this).val();
                    html = '';
                    $.ajax({
                        //请求方式
                        type : "POST",
                        dataType: "json",
                        url : "student_information/point",
                        data : {id:id},
                        success : function(result) {
                            $.each(result, function(index, value) {

                                html+='<option value="'+value.name+'" >'+value.name+'</option>';
                            });

                            $('#c-point').html(html);
                        },
                        error : function(e){
                            console.log(e.status);
                            console.log(e.responseText);
                        }

                    });

                });

                /*$('#c-teacher_span').on('click',function(){
                    Fast.api.open(Fast.api.fixurl('auth/admin/index1'),'选择老师',{
                        area:["80%","80%"],
                    })

                })*/

                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
